#include "process.h"
#include <time.h>
#include <stdlib.h>

typedef void (*call_t)(const char* tips, double total, double current);
double total = 1024.0;
double speed[] = {10.0, 0.01, 0.2, 0.02, 0.1, 1};

void download(double total, call_t cb)
{
    srand(time(NULL));
    double current = 0.0;
    while(current <= total)
    {
        cb("下载中", total, current);
        if(current >= total)
            break;

        //下载速度
        int random = rand() % 6;
        usleep(5000);
        current += speed[random];
        if(current >= total)
            current = total; 
    }
}

void updownload(double total, call_t cb)
{
    srand(time(NULL));
    double current = 0.0;
    while(current <= total)
    {
        cb("上传中", total, current);
        if(current >= total)
            break;

        int random = rand() % 6;
        usleep(5000);
        current += speed[random];
        if(current >= total)
            current = total; 
    }
}

int main()
{
    download(2048.0, FlushProcess);
    printf("download 2048.0MB done\n");
    download(1024.0, FlushProcess);
    printf("download 1024.0MB done\n");
    download(512.0, FlushProcess);
    printf("download 512.0MB done\n");
    updownload(1024.0, FlushProcess);
    printf("updownload 1024.0MB done\n");

    return 0;
}
